#pragma once
#ifndef IFCRE_SHADER_CONSTS_H_
#define IFCRE_SHADER_CONSTS_H_

namespace ifcre {
	namespace sc {
		static const char* f_axis = "#version 460\r\n"
			"layout(location = 0) flat in vec3 color;\r\n"
			"layout(location = 0) out vec4 FragColor;\r\n"
			"void main(){\r\n"
			"FragColor = vec4(color, 1.0);\r\n"
			"}\r\n";
		static const char* v_axis = "#version 460\r\n"
			"layout(location = 0) in vec3 aPos;\r\n"
			"layout(location = 0) flat out vec3 color;\r\n"
			"layout(std140, binding = 0)uniform TransformsUBO{\r\n"
			"mat4 proj_view_model;       // 0 ~ 64\r\n"
			"} ubo;\r\n"
			"void main(){\r\n"
			"int index = gl_VertexID >> 1;\r\n"
			"switch(index){\r\n"
			"case 0: color = vec3(1.0, 0.0, 0.0); break;\r\n"
			"case 1: color = vec3(0.0, 0.0, 1.0); break;\r\n"
			"case 2: color = vec3(0.0, 1.0, 0.0); break;\r\n"
			"default: color = vec3(1.0, 1.0, 1.0); break;\r\n"
			"}\r\n"
			"gl_Position = ubo.proj_view_model * vec4(aPos, 1.0);\r\n"
			"}\r\n";

		static const char* v_axis_vk = "#version 460\r\n"
			"layout(location = 0) in vec3 aPos;\r\n"
			"layout(location = 0) flat out vec3 color;\r\n"
			"layout(std140, binding = 0)uniform TransformMVPUBO{\r\n"
			"mat4 proj_view_model;       // 0 ~ 64\r\n"
			"} ubo;\r\n"
			"void main(){\r\n"
			"int index = gl_VertexIndex >> 1;\r\n"
			"switch(index){\r\n"
			"case 0: color = vec3(1.0, 0.0, 0.0); break;\r\n"
			"case 1: color = vec3(0.0, 0.0, 1.0); break;\r\n"
			"case 2: color = vec3(0.0, 1.0, 0.0); break;\r\n"
			"default: color = vec3(1.0, 1.0, 1.0); break;\r\n"
			"}\r\n"
			"gl_Position = ubo.proj_view_model * vec4(aPos, 1.0);\r\n"
			"}\r\n";
		static const char* f_bbx = "#version 460\r\n"
			"layout(location = 0) out vec4 FragColor;\r\n"
			"void main()\r\n"
			"{\r\n"
			"FragColor = vec4(1.0, 0.6, 0.0, 1.0);\r\n"
			"}\r\n";

		static const char* v_bbx = "#version 460\r\n"
			"layout(location = 0) in vec3 aPos;\r\n"
			"layout(std140, binding = 0)uniform TransformsUBO{\r\n"
			"mat4 proj_view_model;			// 0 ~ 64\r\n"
			"mat4 model;						// 64 ~ 128\r\n"
			"vec4 uUserClipPlane;			// 128 ~ 144\r\n"
			"vec4 uUserClipBox[6];			// 144 ~ 240\r\n"
			"vec4 drawing_plane;				// 240 ~ 256\r\n"
			"int showTileView;				// 256 ~ 260\r\n"
			"} ubo;\r\n"
			"void main()\r\n"
			"{\r\n"
			"gl_Position = ubo.proj_view_model * vec4(aPos, 1.0);\r\n"
			"}\r\n";
		static const char* f_chosen_test = "#version 460\r\n"
			"layout(location = 0) in vec4 vGoColor;\r\n"
			"layout(location = 1) in vec3 vNormal;\r\n"
			"in vec3 vFragPos;\r\n"
			"layout(location = 3) flat in int vComp;\r\n"
			"layout(location = 4) in float vDistance;\r\n"
			"layout(location = 5) in float vDistanceM[7];\r\n"
			"layout(std140, binding = 1)uniform IFCRenderUBO{\r\n"
			"int h_comp;				// 0 ~ 16\r\n"
			"vec3 cameraDirection;	// 16 ~ 32\r\n"
			"vec3 cameraPosition;	// 32 ~ 48\r\n"
			"} ubo;\r\n"
			"layout(location = 0) out vec4 FragColor;\r\n"
			"void main()\r\n"
			"{\r\n"
			"for(int i=0;i<6;i++){\r\n"
			"if(vDistanceM[i]<0.0)\r\n"
			"discard;\r\n"
			"}\r\n"
			"if(vDistance<0.0)\r\n"
			"discard;\r\n"
			"if(vDistanceM[6] > 0.0) discard;\r\n"
			"vec4 color = vGoColor / 2.0 + vec4(0.0, 0.5, 0.0, 0.0);\r\n"
			"if (ubo.h_comp == vComp) {\r\n"
			"color = vGoColor / 4.0 * 3.0 + vec4(0.0, 0.25, 0.0, 0.0);\r\n"
			"}\r\n"
			"vec3 norm = normalize(vNormal);\r\n"
			"vec4 diffuse = max(dot(norm, -ubo.cameraDirection), 0.0) * color * 0.3;\r\n"
			"vec4 tcolor = color * 0.7 + diffuse;\r\n"
			"FragColor = vec4(tcolor.xyz, vGoColor.a);\r\n"
			"}\r\n";

		static const char* v_chosen_test = "#version 460\r\n"
			"layout(location = 0) in vec3 aPos;\r\n"
			"layout(location = 1) in vec3 aNormal;\r\n"
			"layout(location = 2) in vec4 aColor;\r\n"
			"layout(location = 3) in int aComp;\r\n"
			"layout(location = 4) in int alou;\r\n"
			"layout(std140, binding = 0)uniform TransformsUBO{\r\n"
			"mat4 proj_view_model;			// 0 ~ 64\r\n"
			"mat4 model;						// 64 ~ 128\r\n"
			"vec4 uUserClipPlane;			// 128 ~ 144\r\n"
			"vec4 uUserClipBox[6];			// 144 ~ 240\r\n"
			"vec4 drawing_plane;				// 240 ~ 256\r\n"
			"int showTileView;				// 256 ~ 260\r\n"
			"} ubo;\r\n"
			"layout(std140, binding = 3)uniform StoreyOffsetTransformUBO{\r\n"
			"mat4 storeyOffset_mat[100];		// 0 ~ 6400\r\n"
			"//int floorIndex[100];			// 6400 ~ 6800\r\n"
			"} sotubo;\r\n"
			"layout(location = 0) out vec4 vGoColor;\r\n"
			"layout(location = 1) out vec3 vNormal;\r\n"
			"out vec3 vFragPos;\r\n"
			"layout(location = 3) flat out int vComp;\r\n"
			"layout(location = 4) out float vDistance;\r\n"
			"layout(location = 5) out float vDistanceM[7];\r\n"
			"void main()\r\n"
			"{\r\n"
			"vGoColor = aColor;\r\n"
			"vComp = aComp;\r\n"
			"vNormal=aNormal;\r\n"
			"vec4 p = vec4(aPos, 1.0);\r\n"
			"vec4 eyePos;\r\n"
			"if(ubo.showTileView > 0)\r\n"
			"eyePos = ubo.model * sotubo.storeyOffset_mat[alou] * p;\r\n"
			"else\r\n"
			"eyePos = ubo.model * p;\r\n"
			"vFragPos = eyePos.xyz;\r\n"
			"vDistance = dot(vFragPos, ubo.uUserClipPlane.xyz) - ubo.uUserClipPlane.w;\r\n"
			"for(int i=0;i<6;i++){\r\n"
			"vDistanceM[i]=dot(eyePos.xyz, ubo.uUserClipBox[i].xyz) - ubo.uUserClipBox[i].w;\r\n"
			"}\r\n"
			"vDistanceM[6] = eyePos.y - (ubo.model * ubo.drawing_plane).y;\r\n"
			"if(ubo.showTileView > 0)\r\n"
			"gl_Position = ubo.proj_view_model * sotubo.storeyOffset_mat[alou] * vec4(aPos, 1.0);\r\n"
			"else\r\n"
			"gl_Position = ubo.proj_view_model * vec4(aPos, 1.0);\r\n"
			"}\r\n";
		static const char* f_clp_plane = "#version 460\r\n"
			"layout(location = 0) flat in int thisid;\r\n"
			"layout(location = 0) out vec4 FragColor;\r\n"
			"uniform int ui_id;\r\n"
			"uniform vec3 this_color;\r\n"
			"void main(){\r\n"
			"FragColor = vec4(this_color, .2);\r\n"
			"if(ui_id == thisid){\r\n"
			"FragColor = vec4(this_color / 2. , 1.);\r\n"
			"}\r\n"
			"}\r\n";

		static const char* v_clp_plane = "#version 460\r\n"
			"layout(location = 0) in vec3 aPos;\r\n"
			"layout(location = 1) in int this_id;\r\n"
			"layout(std140, binding = 0)uniform TransformsUBO{\r\n"
			"mat4 proj_view_model;       // 0 ~ 64\r\n"
			"} ubo;\r\n"
			"layout (location = 0)flat out int thisid;\r\n"
			"void main()\r\n"
			"{\r\n"
			"thisid = this_id;\r\n"
			"// gl_Position = projection * modelview * vec4(aPos, 1.0);\r\n"
			"gl_Position = ubo.proj_view_model * vec4(aPos, 1.0);\r\n"
			"}\r\n";
		static const char* f_clp_ui_plane = "#version 460\r\n"
			"layout(location = 0) out int FragId;\r\n"
			"layout(location = 0) flat in int id;\r\n"
			"void main(){\r\n"
			"FragId = id;\r\n"
			"}\r\n";

		static const char* v_clp_ui_plane = "#version 460\r\n"
			"layout(location = 0) in vec3 aPos;\r\n"
			"layout(location = 1) in int aid;\r\n"
			"layout(std140, binding = 0)uniform TransformsUBO{\r\n"
			"mat4 proj_view_model;       // 0 ~ 64\r\n"
			"} ubo;\r\n"
			"layout (location = 0) flat out int id;\r\n"
			"void main()\r\n"
			"{\r\n"
			"id = aid;\r\n"
			"gl_Position = ubo.proj_view_model * vec4(aPos, 1.0);\r\n"
			"}\r\n";
		static const char* f_collision = "#version 460\r\n"
			"#define PI 3.14159265358979323846\r\n"
			"layout(location = 0)in float vDistance;\r\n"
			"layout(location = 1)in float vDistanceM[6];\r\n"
			"uniform vec2 u_resolution;\r\n"
			"uniform float alpha;\r\n"
			"layout(location = 0)out vec4 FragColor;\r\n"
			"vec2 rotate2D(vec2 _st,float _angle){\r\n"
			"_st-=0.5;\r\n"
			"_st = mat2(cos(_angle),-sin(_angle),\r\n"
			"sin(_angle),cos(_angle))*_st;\r\n"
			"_st+=0.5;\r\n"
			"return _st;\r\n"
			"}\r\n"
			"vec2 tile(vec2 _st, float _zoom){\r\n"
			"_st*=_zoom;\r\n"
			"return fract(_st);\r\n"
			"}\r\n"
			"void main()\r\n"
			"{\r\n"
			"for(int i=0;i<6;i++){\r\n"
			"if(vDistanceM[i]<0.0)\r\n"
			"discard;\r\n"
			"}\r\n"
			"if(vDistance<0.0)\r\n"
			"discard;\r\n"
			"vec2 st = gl_FragCoord.xy/u_resolution;\r\n"
			"vec3 outColor=vec3(1.0,0.3729,0.4061);\r\n"
			"vec3 one=vec3(1.,1.,1.);\r\n"
			"st=tile(st,7.0);\r\n"
			"st=rotate2D(st,PI*0.25);\r\n"
			"float fin = mod(st.x,.1);\r\n"
			"fin=smoothstep(.04,.06,fin);\r\n"
			"outColor=mix(outColor,one ,fin*.5);\r\n"
			"FragColor = vec4(outColor, 0.5);\r\n"
			"}\r\n";

		static const char* v_collision = "#version 460\r\n"
			"layout (location = 0) in vec3 aPos;\r\n"
			"layout (location = 1) in vec3 aNormal;\r\n"
			"layout (location = 2) in vec4 aColor;\r\n"
			"layout (location = 3) in int aCompId;\r\n"
			"layout(location = 4) in int alou;\r\n"
			"layout(std140, binding = 0)uniform TransformsUBO{\r\n"
			"mat4 proj_view_model;			// 0 ~ 64\r\n"
			"mat4 model;						// 64 ~ 128\r\n"
			"vec4 uUserClipPlane;			// 128 ~ 144\r\n"
			"vec4 uUserClipBox[6];			// 144 ~ 240\r\n"
			"vec4 drawing_plane;				// 240 ~ 256\r\n"
			"int showTileView;				// 256 ~ 260\r\n"
			"} ubo;\r\n"
			"layout(std140, binding = 3)uniform StoreyOffsetTransformUBO{\r\n"
			"mat4 storeyOffset_mat[100];		// 0 ~ 6400\r\n"
			"} sotubo;\r\n"
			"layout(location = 0) out float vDistance;\r\n"
			"layout(location = 1) out float vDistanceM[7];\r\n"
			"void main()\r\n"
			"{\r\n"
			"vec4 p = vec4(aPos, 1.0);\r\n"
			"vec4 eyePos;\r\n"
			"if(ubo.showTileView > 0)\r\n"
			"eyePos = ubo.model * sotubo.storeyOffset_mat[alou] * p;\r\n"
			"else\r\n"
			"eyePos = ubo.model * p;\r\n"
			"vDistance = dot(eyePos.xyz, ubo.uUserClipPlane.xyz) - ubo.uUserClipPlane.w;\r\n"
			"for(int i=0;i<6;i++){\r\n"
			"vDistanceM[i]=dot(eyePos.xyz, ubo.uUserClipBox[i].xyz) - ubo.uUserClipBox[i].w;\r\n"
			"}\r\n"
			"vDistanceM[6] = eyePos.y - (ubo.model * ubo.drawing_plane).y;\r\n"
			"gl_Position = ubo.proj_view_model * sotubo.storeyOffset_mat[alou] * vec4(aPos, 1.0);\r\n"
			"}\r\n";
		static const char* f_comp_id_write = "#version 460\r\n"
			"layout(location = 0) out int FragId;\r\n"
			"layout(location = 0) flat in int vCompId;\r\n"
			"layout(location = 1) in float vDistance;\r\n"
			"layout(location = 2) in float vDistanceM[7];\r\n"
			"// vec3 int2rgb(int num){\r\n"
			"//     float b = (num % 256) / 256.;\r\n"
			"//     num = num >> 8;\r\n"
			"//     float g = (num % 256) / 256.;\r\n"
			"//     num = num >> 8;\r\n"
			"//     float r = (num % 256) / 256.;\r\n"
			"//     return vec3(r, g, b);\r\n"
			"// }\r\n"
			"void main(){\r\n"
			"for(int i=0;i<6;i++){\r\n"
			"if(vDistanceM[i]<0.0)\r\n"
			"discard;\r\n"
			"}\r\n"
			"if(vDistance<0.0)\r\n"
			"//FragId=-1;\r\n"
			"discard;\r\n"
			"// FragId=vec4(int2rgb(comp),1.);\r\n"
			"if(vDistanceM[6] > 0.03) discard;\r\n"
			"FragId = vCompId;\r\n"
			"}\r\n";

		static const char* v_comp_id_write = "#version 460\r\n"
			"layout (location = 0) in vec3 aPos;\r\n"
			"layout (location = 1) in vec3 aNormal;\r\n"
			"layout (location = 2) in vec4 aColor;\r\n"
			"layout (location = 3) in int aCompId;\r\n"
			"layout(location = 4) in int alou;\r\n"
			"layout(std140, binding = 0)uniform TransformsUBO{\r\n"
			"mat4 proj_view_model;			// 0 ~ 64\r\n"
			"mat4 model;						// 64 ~ 128\r\n"
			"vec4 uUserClipPlane;			// 128 ~ 144\r\n"
			"vec4 uUserClipBox[6];			// 144 ~ 240\r\n"
			"vec4 drawing_plane;				// 240 ~ 256\r\n"
			"int showTileView;				// 256 ~ 260\r\n"
			"} ubo;\r\n"
			"layout(std140, binding = 3)uniform StoreyOffsetTransformUBO{\r\n"
			"mat4 storeyOffset_mat[100];		// 0 ~ 6400\r\n"
			"int floorIndex[100];			// 6400 ~ 6800\r\n"
			"} sotubo;\r\n"
			"layout (location = 0) flat out int vCompId;\r\n"
			"layout (location = 1) out float vDistance;\r\n"
			"layout (location = 2) out float vDistanceM[7];\r\n"
			"void main()\r\n"
			"{\r\n"
			"vCompId = aCompId;\r\n"
			"vec4 p = vec4(aPos, 1.0);\r\n"
			"vec4 eyePos;\r\n"
			"if(ubo.showTileView > 0)\r\n"
			"eyePos = ubo.model * sotubo.storeyOffset_mat[alou] * p;\r\n"
			"else\r\n"
			"eyePos = ubo.model * p;\r\n"
			"vDistance = dot(eyePos.xyz, ubo.uUserClipPlane.xyz) - ubo.uUserClipPlane.w;\r\n"
			"for(int i=0;i<6;i++){\r\n"
			"vDistanceM[i]=dot(eyePos.xyz, ubo.uUserClipBox[i].xyz) - ubo.uUserClipBox[i].w;\r\n"
			"}\r\n"
			"vDistanceM[6] = eyePos.y - (ubo.model * ubo.drawing_plane).y;\r\n"
			"if(ubo.showTileView > 0)\r\n"
			"gl_Position = ubo.proj_view_model * sotubo.storeyOffset_mat[alou] * vec4(aPos, 1.0);\r\n"
			"else\r\n"
			"gl_Position = ubo.proj_view_model * vec4(aPos, 1.0);\r\n"
			"}\r\n";
		static const char* f_drawing_match = "#version 460\r\n"
			"out vec4 FragColor;\r\n"
			"in vec2 TexCoords;\r\n"
			"uniform sampler2D Drawing;\r\n"
			"void main(){\r\n"
			"vec4 color = texture(Drawing, TexCoords);\r\n"
			"if(color.a < 0.1)\r\n"
			"discard;\r\n"
			"FragColor = vec4(color.rgb, 0.6);\r\n"
			"}\r\n";

		static const char* v_drawing_match = "#version 460\r\n"
			"layout (location = 0) in vec3 aPos;\r\n"
			"layout (location = 1) in vec2 aTexCoords;\r\n"
			"layout(std140, binding = 2)uniform TransformsUBO{\r\n"
			"mat4 proj_view_model;       // 0 ~ 64\r\n"
			"} ubo;\r\n"
			"out vec2 TexCoords;\r\n"
			"void main(){\r\n"
			"gl_Position = ubo.proj_view_model * vec4(aPos, 1.0);\r\n"
			"TexCoords = aTexCoords;\r\n"
			"}\r\n";
		static const char* f_edge = "#version 460\r\n"
			"layout(location = 0)in vec4 vGoColor;\r\n"
			"layout(location = 1)in float vDistance;\r\n"
			"layout(location = 2)in float vDistanceM[7];\r\n"
			"layout(location = 0)out vec4 FragColor;\r\n"
			"void main()\r\n"
			"{\r\n"
			"for(int i=0;i<6;i++){\r\n"
			"if(vDistanceM[i]<0.0)\r\n"
			"discard;\r\n"
			"}\r\n"
			"if(vDistance<0.0)\r\n"
			"discard;\r\n"
			"if(vDistanceM[6] > 0.0) discard;\r\n"
			"FragColor = vGoColor;\r\n"
			"//if(vDistanceM[6] > 0.0) FragColor = vec4(1.0, 0.6, 0.0, 1.0);\r\n"
			"}\r\n";

		static const char* v_edge = "#version 460\r\n"
			"layout (location = 0) in vec3 aPos;\r\n"
			"layout (location = 1) in vec3 aNormal;\r\n"
			"layout (location = 2) in vec4 aColor;\r\n"
			"layout (location = 3) in int aCompId;\r\n"
			"layout(location = 4) in int alou;\r\n"
			"layout(std140, binding = 0)uniform TransformsUBO{\r\n"
			"mat4 proj_view_model;			// 0 ~ 64\r\n"
			"mat4 model;						// 64 ~ 128\r\n"
			"vec4 uUserClipPlane;			// 128 ~ 144\r\n"
			"vec4 uUserClipBox[6];			// 144 ~ 240\r\n"
			"vec4 drawing_plane;				// 240 ~ 256\r\n"
			"int showTileView;				// 256 ~ 260\r\n"
			"} ubo;\r\n"
			"layout(std140, binding = 3)uniform StoreyOffsetTransformUBO{\r\n"
			"mat4 storeyOffset_mat[100];		// 0 ~ 6400\r\n"
			"//int floorIndex[100];			// 6400 ~ 6800\r\n"
			"} sotubo;\r\n"
			"layout(location = 0) out vec4 vGoColor;\r\n"
			"layout(location = 1) out float vDistance;\r\n"
			"layout(location = 2) out float vDistanceM[7];\r\n"
			"void main()\r\n"
			"{\r\n"
			"vGoColor = vec4(aColor.xyz * 0.5, aColor.w);\r\n"
			"vec4 p = vec4(aPos, 1.0);\r\n"
			"vec4 eyePos;\r\n"
			"if(ubo.showTileView > 0)\r\n"
			"eyePos = ubo.model * sotubo.storeyOffset_mat[alou] * p;\r\n"
			"else\r\n"
			"eyePos = ubo.model * p;\r\n"
			"vDistance = dot(eyePos.xyz, ubo.uUserClipPlane.xyz) - ubo.uUserClipPlane.w;\r\n"
			"for(int i=0;i<6;i++){\r\n"
			"vDistanceM[i]=dot(eyePos.xyz, ubo.uUserClipBox[i].xyz) - ubo.uUserClipBox[i].w;\r\n"
			"}\r\n"
			"vDistanceM[6] = eyePos.y - (ubo.model * ubo.drawing_plane).y;\r\n"
			"if(ubo.showTileView > 0)\r\n"
			"gl_Position = ubo.proj_view_model * sotubo.storeyOffset_mat[alou] * vec4(aPos, 1.0);\r\n"
			"else\r\n"
			"gl_Position = ubo.proj_view_model * vec4(aPos, 1.0);\r\n"
			"}\r\n";
		static const char* f_gizmo = "#version 460\r\n"
			"layout(location = 0) out vec4 FragColor;\r\n"
			"in vec2 TexCoord;\r\n"
			"in flat int thisid;\r\n"
			"uniform sampler2D ourTexture;\r\n"
			"void main(){\r\n"
			"vec4 tempColor = texture(ourTexture,TexCoord);\r\n"
			"if(thisid > 0){\r\n"
			"tempColor = tempColor*0.75+ vec4(0., 0.25, 0.25, 0.);\r\n"
			"}\r\n"
			"FragColor = tempColor;\r\n"
			"}\r\n";

		static const char* v_gizmo = "#version 460\r\n"
			"layout(location = 0) in vec3 aPos;\r\n"
			"layout(location = 1) in vec2 uvs;\r\n"
			"layout(location = 2) in int aid;\r\n"
			"layout(std140, binding = 0)uniform TransformsUBO{\r\n"
			"mat4 view_matrix;   // 0 ~ 64\r\n"
			"} ubo;\r\n"
			"uniform int hover_id;\r\n"
			"out vec2 TexCoord;\r\n"
			"out flat int thisid;\r\n"
			"void main(){\r\n"
			"TexCoord = uvs;\r\n"
			"gl_Position = ubo.view_matrix * vec4(aPos, 1.0) + vec4(.9, .8, 0., 0.);\r\n"
			"thisid = 0;\r\n"
			"if(hover_id == aid)\r\n"
			"thisid = 1;\r\n"
			"}\r\n";
		static const char* f_gizmo_ui = "#version 460\r\n"
			"layout(location = 0) out int FragId;\r\n"
			"layout(location = 0) flat in int id;\r\n"
			"void main(){\r\n"
			"FragId = id;\r\n"
			"}\r\n";

		static const char* v_gizmo_ui = "#version 460\r\n"
			"layout(location = 0) in vec3 aPos;\r\n"
			"layout(location = 1) in vec2 uvs;\r\n"
			"layout(location = 2) in int aid;\r\n"
			"layout(std140, binding = 0)uniform TransformsUBO{\r\n"
			"mat4 view_matrix;   // 0 ~ 64\r\n"
			"} ubo;\r\n"
			"layout (location = 0) flat out int id;\r\n"
			"void main(){\r\n"
			"id = aid;\r\n"
			"gl_Position = ubo.view_matrix * vec4(aPos, 1.0) + vec4(.9, .8, 0., 0.);\r\n"
			"}\r\n";
		static const char* f_grid = "#version 460\r\n"
			"in vec3 lineColor;\r\n"
			"in float lineType;\r\n"
			"flat in vec3 startPos;\r\n"
			"in vec3 vertPos;\r\n"
			"uniform vec2  u_resolution;\r\n"
			"layout(location = 0) out vec4 FragColor;\r\n"
			"void main() {\r\n"
			"if(lineType < 0) {\r\n"
			"vec2  dir  = (vertPos.xy-startPos.xy) * u_resolution/2.0;\r\n"
			"float dist = length(dir);\r\n"
			"uint bit = uint(round(dist / 2.0f)) & 15U;\r\n"
			"if ((0x18ff & (1U<<bit)) == 0U)\r\n"
			"discard;\r\n"
			"}\r\n"
			"FragColor = vec4(lineColor, 1.0);\r\n"
			"}\r\n";

		static const char* v_grid = "#version 460\r\n"
			"layout(location = 0) in vec3 aPos;\r\n"
			"layout(location = 1) in vec3 aColor;\r\n"
			"layout(location = 2) in float alineType;\r\n"
			"out float lineType;\r\n"
			"flat out vec3 startPos;\r\n"
			"out vec3 vertPos;\r\n"
			"out vec3 lineColor;\r\n"
			"layout(std140, binding = 0)uniform TransformsUBO{\r\n"
			"mat4 proj_view_model;       // 0 ~ 64\r\n"
			"} ubo;\r\n"
			"void main() {\r\n"
			"lineColor = aColor;\r\n"
			"lineType = alineType;\r\n"
			"vec4 pos    = ubo.proj_view_model * vec4(aPos, 1.0);\r\n"
			"gl_Position = pos;\r\n"
			"vertPos     = pos.xyz / pos.w;\r\n"
			"startPos    = vertPos;\r\n"
			"}\r\n";
		static const char* f_image_effect = "#version 460\r\n"
			"out vec4 FragColor;\r\n"
			"in vec2 f_texcoord[5];\r\n"
			"uniform sampler2D screenTexture;\r\n"
			"uniform sampler2D depthNormalTexture;\r\n"
			"uniform int this_flag;\r\n"
			"const vec2 _Sensitivity = vec2(1.0, 1.0);\r\n"
			"const vec4 _EdgeColor = vec4(0.0, 0.0, 0.0, 1.0);\r\n"
			"const vec4 _BackgroundColor = vec4(1.0, 1.0, 1.0, 1.0);\r\n"
			"const float _EdgeOnly = 0.5f;\r\n"
			"float DecodeFloatRG(in vec2 enc)\r\n"
			"{\r\n"
			"vec2 kDecodeDot = vec2(1.0, 1/255.0);\r\n"
			"return dot( enc, kDecodeDot );\r\n"
			"}\r\n"
			"float CheckSame(in vec4 col1,in vec4 col2){\r\n"
			"float d1 = DecodeFloatRG(col1.zw);\r\n"
			"vec2 normal1 = col1.xy;\r\n"
			"float d2 = DecodeFloatRG(col2.zw);\r\n"
			"vec2 normal2 = col2.xy;\r\n"
			"vec2 diffNormal = abs(normal2 - normal1) * _Sensitivity.x;\r\n"
			"float diffDepth = abs(d2 - d1) * _Sensitivity.y;\r\n"
			"int isSameNormal = (diffNormal.x + diffNormal.y) < 0.1?1:0;\r\n"
			"int isSameDepth = (diffDepth < (0.1 * d1)) ? 1:0;\r\n"
			"return (isSameDepth * isSameNormal != 0) ? 1.0 : 0.0;\r\n"
			"}\r\n"
			"void main(){\r\n"
			"vec4 sample1 = texture(depthNormalTexture, f_texcoord[1]);\r\n"
			"vec4 sample2 = texture(depthNormalTexture, f_texcoord[2]);\r\n"
			"vec4 sample3 = texture(depthNormalTexture, f_texcoord[3]);\r\n"
			"vec4 sample4 = texture(depthNormalTexture, f_texcoord[4]);\r\n"
			"float edge = 1.0f;\r\n"
			"edge *= CheckSame(sample1, sample2);\r\n"
			"edge *= CheckSame(sample3, sample4);\r\n"
			"edge = 1.0 - edge;\r\n"
			"vec4 withEdge = mix(texture(screenTexture, f_texcoord[0]), _EdgeColor, edge);\r\n"
			"// vec4 onlyEdge = mix(_BackgroundColor, _EdgeColor, edge);\r\n"
			"// vec3 col = mix(withEdge, onlyEdge, _EdgeOnly).rgb;\r\n"
			"// FragColor = vec4(col, 1.0);\r\n"
			"#define ONLY_DEPTH_NROMAL_RES\r\n"
			"#ifndef ONLY_DEPTH_NROMAL_RES\r\n"
			"FragColor = vec4(withEdge.rgb, 1.0);\r\n"
			"#else\r\n"
			"vec3 textcolor = texture(screenTexture, f_texcoord[0]).rgb;\r\n"
			"float judgement = textcolor.x * textcolor.y * textcolor.z;\r\n"
			"if(this_flag == 0 && judgement > 0.9999)\r\n"
			"discard;\r\n"
			"FragColor = vec4(texture(screenTexture, f_texcoord[0]).rgb,1.0);\r\n"
			"#endif\r\n"
			"}\r\n";

		static const char* v_image_effect = "#version 460\r\n"
			"layout(location = 0) in vec2 pos;\r\n"
			"layout(location = 1) in vec2 texcoord;\r\n"
			"out vec2 f_texcoord[5];\r\n"
			"float _SampleDistance = 1.0;\r\n"
			"uniform vec2 screenTexTexelSize;\r\n"
			"uniform float scale;\r\n"
			"void main(){\r\n"
			"f_texcoord[0] = texcoord;\r\n"
			"f_texcoord[1] = texcoord + screenTexTexelSize.xy * vec2(1, 1) * _SampleDistance;\r\n"
			"f_texcoord[2] = texcoord + screenTexTexelSize.xy * vec2(-1, -1) * _SampleDistance;\r\n"
			"f_texcoord[3] = texcoord + screenTexTexelSize.xy * vec2(-1, 1) * _SampleDistance;\r\n"
			"f_texcoord[4] = texcoord + screenTexTexelSize.xy * vec2(1, -1) * _SampleDistance;\r\n"
			"vec2 nowpos = pos * scale + vec2(1. - scale);\r\n"
			"gl_Position = vec4(nowpos, 0.0, 1.0);\r\n"
			"}\r\n";
		static const char* f_normal_depth_write = "#version 460\r\n"
			"out vec4 FragColor;\r\n"
			"in vec3 f_normal;\r\n"
			"vec2 EncodeViewNormalStereo( vec3 n )\r\n"
			"{\r\n"
			"float kScale = 1.7777;\r\n"
			"vec2 enc;\r\n"
			"enc = n.xy / (n.z+1);\r\n"
			"enc /= kScale;\r\n"
			"enc = enc*0.5+0.5;\r\n"
			"return enc;\r\n"
			"}\r\n"
			"vec2 EncodeFloatRG( float v )\r\n"
			"{\r\n"
			"vec2 kEncodeMul = vec2(1.0, 255.0);\r\n"
			"float kEncodeBit = 1.0/255.0;\r\n"
			"vec2 enc = kEncodeMul * v;\r\n"
			"// enc.x = enc.x - int(enc.x);\r\n"
			"// enc.y = enc.y - int(enc.y);\r\n"
			"enc = fract(enc);\r\n"
			"enc.x -= enc.y * kEncodeBit;\r\n"
			"return enc;\r\n"
			"}\r\n"
			"void main(){\r\n"
			"FragColor = vec4(EncodeViewNormalStereo(f_normal), EncodeFloatRG(1 - gl_FragCoord.z));\r\n"
			"// float d = 1 - gl_FragCoord.z;\r\n"
			"// FragColor = vec4(d,d,d,1.0);\r\n"
			"// FragColor = vec4(1.0,1.0,1.0,1.0);\r\n"
			"}\r\n";

		static const char* v_normal_depth_write = "#version 460\r\n"
			"layout (location = 0) in vec3 pos;\r\n"
			"layout (location = 1) in vec3 normal;\r\n"
			"uniform mat3 t_inv_model;\r\n"
			"uniform mat3 mv;\r\n"
			"uniform mat4 mvp;\r\n"
			"out vec3 f_normal;\r\n"
			"void main()\r\n"
			"{\r\n"
			"gl_Position = mvp * vec4(pos, 1.0);\r\n"
			"// transform to [0, 1]\r\n"
			"f_normal = t_inv_model * normal;\r\n"
			"}\r\n";
		static const char* f_skybox = "#version 460\r\n"
			"#define PI 3.141592654\r\n"
			"#define Eclipse (PI / 2.)\r\n"
			"in float dep;\r\n"
			"in vec3 dir;\r\n"
			"layout(location = 0) out vec4 FragColor;\r\n"
			"//uniform float Eclipse;\r\n"
			"vec3 damp(float t, vec3 start, vec3 end){\r\n"
			"return start * (1 - t) + end * t;\r\n"
			"}\r\n"
			"float scaleOut(float t){\r\n"
			"if( t >= Eclipse)\r\n"
			"return (t - Eclipse)/( PI - Eclipse);\r\n"
			"return t / Eclipse;\r\n"
			"}\r\n"
			"vec2 cube2sphere(){\r\n"
			"vec3 direciton = normalize(dir);\r\n"
			"float phi = acos(direciton.y);\r\n"
			"float theta = acos(direciton.z / sin(phi));\r\n"
			"return vec2(theta, PI - phi);\r\n"
			"}\r\n"
			"void main(){\r\n"
			"vec3 outColor;\r\n"
			"vec2 thetaphi = cube2sphere();\r\n"
			"if(thetaphi.y >= Eclipse){\r\n"
			"//outColor = damp(scaleOut(thetaphi.y), vec3(0.8789, 0.9062, 0.9570), vec3(0.6015, 0.7070, 0.8906));\r\n"
			"outColor = damp(scaleOut(thetaphi.y), vec3(1., 1., 1.), vec3(1., 1., 1.));\r\n"
			"}\r\n"
			"else{\r\n"
			"//outColor = damp(scaleOut(thetaphi.y), vec3(0.5976, 0.3984, 0.1992), vec3(0.7890, 0.5781, 0.3671));\r\n"
			"outColor = damp(scaleOut(thetaphi.y), vec3(1., 1., 1.), vec3(1., 1., 1.));\r\n"
			"}\r\n"
			"FragColor = vec4(outColor, 1.0);\r\n"
			"}\r\n";

		static const char* v_skybox = "#version 460\r\n"
			"layout(location = 0) in vec3 aPos;\r\n"
			"layout(location = 1) in float depth;\r\n"
			"uniform mat4 view_matrix;\r\n"
			"out float dep;\r\n"
			"out vec3 dir;\r\n"
			"void main(){\r\n"
			"dep = depth;\r\n"
			"dir = aPos;\r\n"
			"vec4 pos = view_matrix * vec4(aPos, 1.0);\r\n"
			"gl_Position = pos.xyww;\r\n"
			"}\r\n";
		static const char* f_skybox1 = "#version 460 core\r\n"
			"out vec4 FragColor;\r\n"
			"in vec3 TexCoords;\r\n"
			"uniform samplerCube skybox;\r\n"
			"void main()\r\n"
			"{\r\n"
			"FragColor = texture(skybox, TexCoords);\r\n"
			"}\r\n";

		static const char* v_skybox1 = "#version 460 core\r\n"
			"layout (location = 0) in vec3 aPos;\r\n"
			"out vec3 TexCoords;\r\n"
			"uniform mat4 projection;\r\n"
			"uniform mat4 view;\r\n"
			"void main()\r\n"
			"{\r\n"
			"TexCoords = aPos;\r\n"
			"vec4 pos = projection * view * vec4(aPos, 1.0);\r\n"
			"gl_Position = pos.xyww;\r\n"
			"}\r\n";
		static const char* f_test = "#version 460\r\n"
			"layout(location = 0) in vec4 vGoColor;\r\n"
			"layout(location = 1) in vec3 vNormal;\r\n"
			"in vec3 vFragPos;\r\n"
			"layout(location = 3) flat in int vComp;\r\n"
			"layout(location = 4) in float vDistance;\r\n"
			"layout(location = 5) in float vDistanceM[7];\r\n"
			"layout(std140, binding = 1)uniform IFCRenderUBO{\r\n"
			"int h_comp;				// 0 ~ 16\r\n"
			"vec3 cameraDirection;	// 16 ~ 32\r\n"
			"vec3 cameraPosition;	// 32 ~ 48\r\n"
			"} ubo;\r\n"
			"uniform float shading_factor = 1.0;\r\n"
			"layout(location = 0) out vec4 FragColor;\r\n"
			"void main()\r\n"
			"{\r\n"
			"for(int i=0;i<6;i++){\r\n"
			"if(vDistanceM[i]<0.0)\r\n"
			"discard;\r\n"
			"}\r\n"
			"if(vDistance<0.0)\r\n"
			"discard;\r\n"
			"if(vDistanceM[6] > 0.0) discard;\r\n"
			"vec4 color = vGoColor;\r\n"
			"if (ubo.h_comp == vComp) {\r\n"
			"color = vGoColor / 4.0 * 3.0 + vec4(0.0, 0.25, 0.0, 0.0);\r\n"
			"}\r\n"
			"vec3 norm = normalize(vNormal);\r\n"
			"vec4 diffuse = max(dot(norm, -ubo.cameraDirection), 0.0) * color * 0.3;\r\n"
			"vec4 tcolor = color * 0.7 + diffuse;\r\n"
			"FragColor = vec4(tcolor.xyz * shading_factor, vGoColor.a);\r\n"
			"}\r\n";

		static const char* v_test = "#version 460\r\n"
			"layout(location = 0) in vec3 aPos;\r\n"
			"layout(location = 1) in vec3 aNormal;\r\n"
			"layout(location = 2) in vec4 aColor;\r\n"
			"layout(location = 3) in int aComp;\r\n"
			"layout(location = 4) in int alou;\r\n"
			"layout(std140, binding = 0)uniform TransformsUBO{\r\n"
			"mat4 proj_view_model;			// 0 ~ 64\r\n"
			"mat4 model;						// 64 ~ 128\r\n"
			"vec4 uUserClipPlane;			// 128 ~ 144\r\n"
			"vec4 uUserClipBox[6];			// 144 ~ 240\r\n"
			"vec4 drawing_plane;				// 240 ~ 256\r\n"
			"int showTileView;				// 256 ~ 260\r\n"
			"} ubo;\r\n"
			"layout(std140, binding = 3)uniform StoreyOffsetTransformUBO{\r\n"
			"mat4 storeyOffset_mat[100];		// 0 ~ 6400\r\n"
			"//int floorIndex[100];			// 6400 ~ 6800\r\n"
			"} sotubo;\r\n"
			"layout(location = 0) out vec4 vGoColor;\r\n"
			"layout(location = 1) out vec3 vNormal;\r\n"
			"out vec3 vFragPos;\r\n"
			"layout(location = 3) flat out int vComp;\r\n"
			"layout(location = 4) out float vDistance;\r\n"
			"layout(location = 5) out float vDistanceM[7];\r\n"
			"void main()\r\n"
			"{\r\n"
			"vGoColor = aColor;\r\n"
			"vComp = aComp;\r\n"
			"vNormal=aNormal;\r\n"
			"vec4 p = vec4(aPos, 1.0);\r\n"
			"vec4 eyePos;\r\n"
			"if(ubo.showTileView > 0)\r\n"
			"eyePos = ubo.model * sotubo.storeyOffset_mat[alou] * p;\r\n"
			"else\r\n"
			"eyePos = ubo.model * p;\r\n"
			"vFragPos = eyePos.xyz;\r\n"
			"vDistance = dot(vFragPos, ubo.uUserClipPlane.xyz) - ubo.uUserClipPlane.w;\r\n"
			"for(int i=0;i<6;i++){\r\n"
			"vDistanceM[i]=dot(eyePos.xyz, ubo.uUserClipBox[i].xyz) - ubo.uUserClipBox[i].w;\r\n"
			"}\r\n"
			"vDistanceM[6] = eyePos.y - (ubo.model * ubo.drawing_plane).y;\r\n"
			"if(ubo.showTileView > 0)\r\n"
			"gl_Position = ubo.proj_view_model * sotubo.storeyOffset_mat[alou] * vec4(aPos, 1.0);\r\n"
			"else\r\n"
			"gl_Position = ubo.proj_view_model * vec4(aPos, 1.0);\r\n"
			"}\r\n";
		static const char* f_text = "#version 460\r\n"
			"in vec2 TexCoords;\r\n"
			"out vec4 color;\r\n"
			"uniform sampler2D text;\r\n"
			"uniform vec3 textColor;\r\n"
			"void main()\r\n"
			"{\r\n"
			"vec4 sampled = vec4(1.0, 1.0, 1.0, texture(text, TexCoords).r);\r\n"
			"color = vec4(textColor, 1.0) * sampled;\r\n"
			"}\r\n";

		static const char* v_text = "#version 460\r\n"
			"layout (location = 0) in vec4 vertex; // <vec2 pos, vec2 tex>\r\n"
			"out vec2 TexCoords;\r\n"
			"uniform vec2 offset;\r\n"
			"uniform mat4 projection;\r\n"
			"void main()\r\n"
			"{\r\n"
			"vec2 truepos = offset + vertex.xy;\r\n"
			"gl_Position = projection * vec4(truepos, 0.0, 1.0);\r\n"
			"TexCoords = vertex.zw;\r\n"
			"}\r\n";
		static const char* v_text3d = "#version 460\r\n"
			"layout(location = 0) in vec3 pos;\r\n"
			"layout(location = 1) in vec2 texcoord;\r\n"
			"out vec2 TexCoords;\r\n"
			"uniform mat4 projection;\r\n"
			"uniform mat4 modelview;\r\n"
			"void main()\r\n"
			"{\r\n"
			"gl_Position = projection * modelview * vec4(pos, 1.0);\r\n"
			"TexCoords = texcoord;\r\n"
			"}\r\n";

		static const char* f_tile_view_drawing = "#version 460\r\n"
			"out vec4 FragColor;\r\n"
			"in vec2 TexCoords;\r\n"
			"uniform sampler2D Drawing;\r\n"
			"void main(){\r\n"
			"vec4 color = texture(Drawing, TexCoords);\r\n"
			"if(color.a < 0.1)\r\n"
			"discard;\r\n"
			"FragColor = vec4(color.rgb, 0.6);\r\n"
			"}\r\n";
		static const char* v_tile_view_drawing = "#version 460\r\n"
			"layout (location = 0) in vec3 aPos;\r\n"
			"layout (location = 1) in vec2 aTexCoords;\r\n"
			"layout(std140, binding = 2)uniform TransformsUBO{\r\n"
			"mat4 proj_view_model;       // 0 ~ 64\r\n"
			"} ubo;\r\n"
			"out vec2 TexCoords;\r\n"
			"void main(){\r\n"
			"gl_Position = ubo.proj_view_model * vec4(aPos, 1.0);\r\n"
			"TexCoords = aTexCoords;\r\n"
			"}\r\n";

	}// shader_consts

}
#endif
